package cn.ubeta.b2c.product;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;

import cn.ubeta.b2c.R;
import cn.ubeta.b2c.common.FragmentActivity;
import cn.ubeta.b2c.navigation.HomeFragment;

/**
 * Created by denny on 2016/10/13.
 */

public class ProductListActivity extends FragmentActivity<ProductListFragment> {

    private static final String PARAM_TITLE = "title";
    private static final String PARAM_ID = "id";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String title = getIntent().getStringExtra(PARAM_TITLE);

        if (TextUtils.isEmpty(title))
            mTitleBar.setTitle("商品列表");
        else
            mTitleBar.setTitle(title);
    }

    @Override
    public ProductListFragment newFragmentInstance() {
        return HomeFragment.newInstance(getIntent().getIntExtra(PARAM_ID, 0));
    }

    /**
     * 跳转到商品列表
     * @param activity
     * @param title
     */
    public static void gotoProductList(Activity activity, String title, int id) {
        Intent intent = new Intent(activity, ProductListActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(PARAM_TITLE, title);
        intent.putExtra(PARAM_ID, id);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.in_right_to_left, android.R.anim.fade_out);
    }
}
